///Replication file for "Drought exposure decreases altruism with salient group identities as key moderator"
/// S. Doring & J. Hall, Nature Climate Change 2023

//Latest run with Stata 17.0 BE on MacOs 13.3.1 
//Last Update June 8, 2023


//NOTE: We use user-written packages and color schemes for visualization in the manuscript. Here we restrict visualization to Stata's default option to increase compatibility and replicability. 


use "Dataset.dta" // requires the file to be in the working directory


***Results for H1 (compare first regression table in the SI)

*a)

//a1
mixed wtr i.Dum_spei_12_av age i.gen edu || adm1: 

//a2
mixed wtr i.Dum_spei_12_av age i.gen edu i.urb || adm1: 

//a3
mixed wtr i.Dum_spei_12_av age i.gen edu ses || adm1: 

//a4
mixed wtr i.Dum_spei_12_av age i.gen edu i.urb ses  || adm1: 


*b) Other Drought indicators 

//b1
mixed wtr i.spei_12spam_dum  age i.gen edu || adm1: 

//b2
mixed wtr i.spei_12spamHV_dum age i.gen edu  || adm1: 

//b3
mixed wtr i.Dum_growendspei_6_min age i.gen edu  || adm1: 

//b4
mixed wtr i.Dum_growendspei_6_av age i.gen edu  || adm1: 

//b5
mixed wtr i.growendspei_6crop_dum age i.gen edu  || adm1: 


***Results for H2 (compare second regression table in the SI)


*2a,b *this is the regression for the H2a,b figure in the main text
mixed wtr c.spei_12_av##i.WTR_sunni age i.gen edu if rel == 1  & eth ==1 || adm1:
//Note: the if condition is necessary to restrict the sample to Sunni Arab respondents

*marginal effects plots H2a (requires to run the regression commnand beforehand)
margins, dydx(WTR_sunni) at(c.spei_12_av=(-2.25(0.15)2.25) (means)) post 
marginsplot,  recast(line)  recastci(rarea)   yline(0)

*marginal effects plots H2a  (requires to run the regression commnand beforehand)
margins WTR_sunni, at(c.spei_12_av=(-2.25(0.25)2.25))
marginsplot,   recast(line)  recastci(rarea)


*2c,d *this is the regression for the H2c,d figure in the main text
mixed wtr c.spei_12_av##i.WTRgroup age i.gen edu if rel == 1 & eth ==1 || adm1:
//Note: the if condition is necessary to restrict the sample to Sunni Arab respondents

*marginal effects plots H2c  (requires to run the regression commnand beforehand)
margins, dydx(WTRgroup) at(c.spei_12_av=(-2.25(0.15)2.25) (means))  post 
marginsplot,  recast(line)  recastci(rarea) 

*marginal effects plots H2c  (requires to run the regression commnand beforehand)
margins WTRgroup, at(c.spei_12_av=(-2.25(0.25)2.25))
marginsplot,  recast(line)  recastci(rarea) 

